package com.gzsxy.rabbitmq.consumer.config;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Date;

/**
 * @Description: TODO
 * @Author: xiaolong
 * @date: 2023/2/13 20:50
 * @Version: 1.0
 */
@Slf4j
@Component
@ConditionalOnProperty(value = "rabbitmq.enable.type",havingValue = "ttl")
public class RabbitMQMessageReceiver {

    public static final String DELAYED_QUEUE_NAME = "delayed.queue";

    /**
     * 消费者 - 死信队列
     * @author
     */
    @RabbitListener(queues = "QD")
    public void receiveD(Message message, Channel channel) throws IOException {
        String msg = new String(message.getBody());
        log.info("当前时间：{},收到死信队列信息{}", new Date().toString(), msg);
        // 业务处理
    }

//    /**
//     * 消费者 - 死信队列
//     * @author
//     */
//    @RabbitListener(queues = "QB")
//    public void receiveB(Message message, Channel channel) throws IOException {
//        String msg = new String(message.getBody());
//        log.info("当前时间：{},收到QB队列信息{}", new Date().toString(), msg);
//        // 业务处理
//    }

    //    @RabbitListener(queues = "QA")
//    public void receiveB(Message message, Channel channel) throws IOException {
//        String msg = new String(message.getBody());
//        log.info("当前时间：{},收到QB队列信息{}", new Date().toString(), msg);
//        // 业务处理
//    }


    /**
     * 消费者 - 基于插件的延时队列
     *
     * @author zhiyuan
     */
    @RabbitListener(queues = "delayed.queue")
    public void receiveDelayedQueue(Message message) {
        String msg = new String(message.getBody());
        log.info("当前时间：{},收到插件延时队列的消息：{}", new Date().toString(), msg);
    }
}
